# rubocop:disable Style/SignalException

fail "Please provide a proper merge request description." if gitlab.mr_body.size < 5

fail "Please add labels to this merge request." if gitlab.mr_labels.empty?

warn "You may want to add ~group::distribution label to this MR for gitlab-insights" unless gitlab.mr_labels.any? { |label| label.start_with?("group::") }

warn "This merge request does not have any assignee yet. Setting an assignee clarifies who needs to take action on the merge request at any given time." unless gitlab.mr_json["assignee"]

has_milestone = !gitlab.mr_json["milestone"].nil?

warn "This merge request does not refer to an existing milestone.", sticky: false unless has_milestone

has_pick_into_stable_label = gitlab.mr_labels.find { |label| label.start_with?('Pick into') }

# rubocop:disable Style/IfUnlessModifier
if gitlab.branch_for_base != "master" && !has_pick_into_stable_label
  warn "Most of the time, all merge requests should target `master`. Otherwise, please set the relevant `Pick into X.Y` label."
end

THROUGHPUT_LABELS = ['Community contribution', 'security', 'bug', 'feature', 'backstage', 'documentation'].freeze
if (gitlab.mr_labels & THROUGHPUT_LABELS).empty?
  warn "This merge request is missing any [throughput labels](https://about.gitlab.com/handbook/engineering/management/throughput)."
end
# rubocop:enable Style/IfUnlessModifier
# rubocop:enable Style/SignalException
